package com.scsystem.xysc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scsystem.xysc.pojo.Order;
import com.scsystem.xysc.service.OrderService;
import com.scsystem.xysc.mapper.OrderMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author sky
* @description 针对表【order】的数据库操作Service实现
* @createDate 2023-11-24 21:33:11
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService{

    @Resource
    private OrderMapper orderMapper;

    /**
     * 条件查询订单信息，传值为null则返回全部信息
     * @param order 查询条件
     * @param page 页码
     * @param count 每页显示的数量
     * @return Page<Order>
     */
    @Override
    public Page<Order> getOrderPage(Order order, int page, int count) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>();
        if (order.getOrderId() != null) {
            queryWrapper
                    .eq("order_id", order.getOrderId());
        }
        if (order.getUserId() != null) {
            queryWrapper
                    .eq("user_id", order.getUserId());
        }
        if (order.getProductId() != null) {
            queryWrapper
                    .eq("product_id", order.getProductId());
        }
        if (order.getAddress() != null) {
            queryWrapper
                    .eq("address", order.getAddress());
        }
        if (order.getPhoneNumber() != null) {
            queryWrapper
                    .eq("Phone_number", order.getPhoneNumber());
        }
        if (order.getStatus() != null) {
            queryWrapper
                    .eq("status", order.getStatus());
        }
        if (order.getCreateDate() != null) {
            queryWrapper
                    .eq("create_date", order.getCreateDate());
        }
        if (order.getQuantity() != null) {
            queryWrapper
                    .eq("quantity", order.getQuantity());
        }if (order.getProductPrice() != null) {
            queryWrapper
                    .eq("product_price", order.getProductPrice());
        }
        if (order.getPaymentTime() != null) {
            queryWrapper
                    .eq("payment_time", order.getPaymentTime());
        }
        if (order.getDeliveryTime() != null) {
            queryWrapper
                    .eq("delivery_time", order.getDeliveryTime());
        }if (order.getEndTime() != null) {
            queryWrapper
                    .eq("end_time", order.getEndTime());
        }
        return orderMapper.selectPage(new Page<>(page, count),queryWrapper);
    }

}




